package com.ruoyi.web.controller.bussiness;

import java.util.List;

import com.ruoyi.entity.po.TActivitySwitch;
import com.ruoyi.service.ITActivitySwitchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 活动列表Controller
 *
 * @author ruoyi
 * @date 2024-12-07
 */
@RestController
@RequestMapping("/activity")
@Api(tags = "PC-2.活动列表")
public class ActivitySwitchController extends BaseController {

    @Autowired
    private ITActivitySwitchService tActivitySwitchService;

    /**
     * 查询活动列表
     */
    @PostMapping("/list")
    @ApiOperation("查询活动列表")
    public TableDataInfo list(@RequestBody TActivitySwitch tActivitySwitch) {
        startPage();
        List<TActivitySwitch> list = tActivitySwitchService.selectTActivitySwitchList(tActivitySwitch);
        return getDataTable(list);
    }

    /**
     * 新增保存活动
     */
    @Log(title = "添加活动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation("新增保存活动")
    public AjaxResult addSave(@RequestBody TActivitySwitch tActivitySwitch) {
        return toAjax(tActivitySwitchService.insertTActivitySwitch(tActivitySwitch));
    }


    /**
     * 修改活动
     */
    @Log(title = "活动修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation("修改活动")
    public AjaxResult editSave(@RequestBody TActivitySwitch tActivitySwitch) {
        return toAjax(tActivitySwitchService.updateTActivitySwitch(tActivitySwitch));
    }

    /**
     * 删除活动
     */
    @Log(title = "删除活动", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    @ApiOperation("删除活动")
    public AjaxResult remove(String ids) {
        return toAjax(tActivitySwitchService.deleteTActivitySwitchByIds(ids));
    }


    @GetMapping("/getStatusByCode")
    @ApiOperation("根据 code 查询活动状态")
    public AjaxResult getStatusByCode(@RequestParam String activityCode) {
        return toAjax(tActivitySwitchService.getStatusByCode(activityCode));
    }

    @Valid
    @Log(title = "开启/关闭活动", businessType = BusinessType.UPDATE)
    @PostMapping("/editStatus")
    @ResponseBody
    @ApiOperation("修改活动状态")
    public AjaxResult enableOrDisable(@NotNull @RequestBody ActivityStatusEditVo activityStatusEditVo) {
        return toAjax(tActivitySwitchService.enableOrDisable(activityStatusEditVo.activityId, activityStatusEditVo.targetStatus));
    }

    @Data
    public static class ActivityStatusEditVo{

        @NotNull
        private Integer activityId;

        @NotNull
        private Boolean targetStatus;

    }

}
